package com.open4cn.simulator.connect.tcp.handler;

import com.open4cn.simulator.core.util.ByteBufUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description 打印输出()日志
 * @Email yinxiaopeng@zj.tech
 * @date 2022-04-05 22:02
 */
@ChannelHandler.Sharable
public class WriteLogHandler extends ChannelOutboundHandlerAdapter {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private String device;

    public WriteLogHandler(String device) {
        this.device = device;
    }

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        logger.info("当前{}设备输出消息=>{}", device, ByteBufUtil.log((ByteBuf) msg));
        super.write(ctx, msg, promise);
    }
}
